package com.david.rabbitmq.spirngboot.controller;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author David
 * @version V1.0
 * @Package com.david.rabbitmq.spirngboot.controller
 * @date 2021/7/18 9:58
 */
@RestController
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @GetMapping(value = "/send/direct/{message}")
    public String sendDirectMessage(@PathVariable("message") String message){
        rabbitTemplate.convertAndSend("boot.bx.direct","boot.direct.key",message);
        return "ok";
    }

    @GetMapping(value = "/send/fanout/{message}")
    public String sendFanoutMessage(@PathVariable("message") String message){
        rabbitTemplate.convertAndSend("boot.bx.fanout","boot.direct.key",message);
        return "ok";
    }

    @GetMapping(value = "/send/topic/{message}")
    public String sendTopicMessage(@PathVariable("message") String message){
        rabbitTemplate.convertAndSend("boot.bx.topic","xxxx.topic.xxx",message);
        return "ok";
    }




}
